package com.hzhc.controller.wxapp;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.common.Base64FileUpload;
import com.hzhc.common.BaseController;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.RectifyCntrService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.vo.RectifyCntrVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 待整改表 前端控制器
 * </p>
 *
 * @author 功不唐捐
 * @since 2024-07-25
 */
@RestController
@RequestMapping("/app")
@RequiredArgsConstructor
public class WxApiRectifyCntrController extends BaseController {
    @Value("${file.rectifyUploadFolder}")
    private String rectifyUploadFolder;
    @Value("${file.rectifyAccessPath}")
    private String rectifyAccessPath;


    private final RectifyCntrService rectifyCntrService;

    /**
     * 待整改 图片上传
     * @return
     */
    @RequestMapping("/addCntrFile")
    public ResultUtil<T> addCntrFile(@RequestBody RectifyCntrVo vo){
        MultipartFile multipartFile = Base64FileUpload.base64ToMultipartFile(vo.getFileRef());
        vo.setFile(multipartFile);
        return rectifyCntrService.addCntrFile(vo,rectifyUploadFolder,rectifyAccessPath);
    }

    /**
     * 待整改 图片上传 修改
     * @return
     */
    @RequestMapping("/updateCntrFile")
    public ResultUtil<T> updateCntrFile(@RequestBody RectifyCntrVo vo){
        MultipartFile multipartFile = Base64FileUpload.base64ToMultipartFile(vo.getFileRef());
        vo.setFile(multipartFile);
        return rectifyCntrService.updateCntrFile(vo,rectifyUploadFolder,rectifyAccessPath);
    }

    /**
     * 待整改 删除
     * @return
     */
    @RequestMapping("/delCntrFile")
    public ResultUtil<T> delCntrFile(@RequestBody RectifyCntrVo vo){
        return rectifyCntrService.delCntrFile(vo);
    }

    /**
     * wx 待整改list
     * @param vo
     * @return
     */
    @RequestMapping("/getRectifyCntrList")
    public ResultUtil<List<RectifyCntrVo>> getRectifyCntrList(@RequestBody RectifyCntrVo vo){
        Page<RectifyCntrVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<RectifyCntrVo> list = rectifyCntrService.getRectifyCntrList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }
}
